package test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;

import static controller.Record.recordExpense;

public class ExpenseRecorder {

    public static void main(String[] args) {
        String filePath = "/Users/jahangir/workspace/PersonalFinanceTracking/Backend/src/test/add"; // 替换为你的文件路径
        readFileAndRecordExpenses(filePath);
    }

    public static void readFileAndRecordExpenses(String filePath) {
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                // 读取金额
                double amount = Double.parseDouble(line.trim());

                // 读取日期并解析
                line = reader.readLine();
                int year = 2024;
                int month = 1;
                int day = Integer.parseInt(line.substring(0, 2));
                int hour = Integer.parseInt(line.substring(2, 4));
                int minute = Integer.parseInt(line.substring(4, 6));
                int second = 0;

                //读取note
                String note = reader.readLine().trim();

                //读取交易类型
                String type = reader.readLine().trim();

                // 记录支出
                recordExpense(amount, type, note, year, month, day, hour, minute, second);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NumberFormatException e) {
            System.out.println("数据格式错误：" + e.getMessage());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
